package com.atguigu.queue;

import org.junit.Test;

import java.util.Random;

public class QueueTest {

    @Test
    public void testQueue1(){
        int opCount=100000;
        LoopQueue<Integer>loopQueue=new LoopQueue<>();
        double time1 = testQueue(loopQueue, opCount);
        System.out.println("LoopQueue，time："+time1);
        QueueArray<Integer>queueArray=new QueueArray<>();
        double time2 = testQueue(queueArray, opCount);
        System.out.println("QueueArray，time："+time2);
    }
    public static double testQueue(Queue<Integer>q,int opCount){
        long startTime = System.currentTimeMillis();
        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            q.enqueue(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            q.dequeue();
        }
        long endTime = System.currentTimeMillis();
        return (endTime-startTime)/1000.0;
    }
}
